const path = require('path');
const webpack = require('webpack');
const {
  CleanWebpackPlugin
} = require('clean-webpack-plugin');
const htmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  entry: './src/main.js',
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist'),
    // publicPath: 'dist/'
  },
  devServer: {
    hot: true,
    open: true
  },
  module: {
    rules: [{
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      }, {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.(png|jpe?g)$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 7 * 1024
          }
        }
      },
      // {
      //   test: /\.html$/,
      //   use: {
      //     loader: 'html-loader',
      //     options: {
      //       attributes: {
      //         list: [{
      //             tag: 'img',
      //             attribute: 'src',
      //             type: 'src'
      //           },
      //           {
      //             tag: 'a',
      //             attribute: 'href',
      //             type: 'src'
      //           }
      //         ]
      //       }
      //     }
      //   }
      // },
      // {
      //   test: /\.md$/,
      //   use: ['html-loader', './src/mark-loader']
      // }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new htmlWebpackPlugin({
      title: 'webpack demo',
      template: 'index.html'
    }),
    new webpack.HotModuleReplacementPlugin()
  ]
}